package com.wc.alorithm_blue_bridge._枚举.赢球票;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/13 9:45
 * @description https://www.lanqiao.cn/problems/94/learning/?page=1&first_category_id=1&second_category_id=3
 */
public class Main {
    /**
     * 思路:
     * 按照题目的想法, 可以从任意一个位置开始
     * 那就枚举所有的位置开始的答案
     * 需要把卡牌取走, 也就是删除, 双链表是最适合的
     * 思路明确, 开始代码
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110;
    static int[] a = new int[N];
    static int[] l = new int[N], r = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        int res = 0;
        // 表示从 i 开始数数
        for (int i = 1; i <= n; i++) {
            int idx = i;
            // 当前数数
            int number = 1;
            // 双循环链表初始化
            for (int j = 1; j <= n; j++) {
                l[j] = j - 1;
                r[j] = j + 1;
            }
            r[n] = 1;
            l[1] = n;
            int ans = 0;
            // 已经取走的个数
            int cnt = 0;
            while (number <= n) {
                if (number == a[idx]) {
                    number = 1;
                    ans += a[idx];
                    r[l[idx]] = r[idx];
                    l[r[idx]] = l[idx];
                    cnt ++;
                } else number++;
                idx = r[idx];
                if (cnt == n) break;
            }
            res = Math.max(res, ans);
        }
        out.println(res);
        out.flush();
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}